//
// Created by xili on 2024/8/25 16:31.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution1 {
public:
    vector <vector<int>> findWinners(vector <vector<int>> &matches) {
        map<int, pair<int, int>> ump;
        for (auto item: matches) {
            ump[item[0]].first++;
            ump[item[1]].second++;
        }
        vector <vector<int>> ans(2);
        for (auto &[p, r]: ump) {
            if (!ump[p].second) {
                ans[0].push_back(p);
            }
            if (ump[p].second == 1) {
                ans[1].push_back(p);
            }
        }
        return ans;
    }
};

class Solution2 {
public:
    vector <vector<int>> findWinners(vector <vector<int>> &matches) {
        unordered_map<int, int> freq;
        for (const auto &match: matches) {
            int winner = match[0], loser = match[1];
            if (!freq.count(winner)) {
                freq[winner] = 0;
            }
            ++freq[loser];
        }
        vector <vector<int>> ans(2);
        for (const auto &[key, value]: freq) {
            if (value < 2) {
                ans[value].push_back(key);
            }
        }
        sort(ans[0].begin(), ans[0].end());
        sort(ans[1].begin(), ans[1].end());
        return ans;
    }
};
